package org.indolphin.algorithm;

public class BinarySearch {

    /**
     * 二分查找
     * @param data
     * @param left
     * @param right
     * @param value
     * @return
     */
    public int find(int[] data, int left, int right, int value) {
        if(left > right) {
            return -1;
        }
        int mid = (left + right) / 2;
        int midVal = data[mid];
        if(value > midVal) {
            return find(data, mid + 1, right, value);
        } else if(value < midVal) {
            return find(data, left, mid-1, value);
        } else {
            return mid;
        }
    }

}
